
#取款机系统 time:20190604  name:yehuiwei

#===================参数定义======================================

'''
状态：0-初始登录状态          1-验证账户密码（正在）
      2-验证账户密码（失败）  3-验证账户密码（成功）
'''
global AccountState_login
AccountState_login = 0

global  Error_Code  #错误码
Error_Code = -1

global uid #验证成功后，账户id
uid = -1

#定义银行账户信息
BlankAccount_list=[
    {'name':'zhangsan','money':10000,'password':'123456'},
    {'name':'lisi','money':20000,'password':'234567'},
    {'name':'wangwu','money':30000,'password':'34567'}]

#==================================================================
#=====================函数构造=====================================
def BankAccount_Login(AccountName,AccountPassword):
    i = 0
    while i < len(BlankAccount_list):
        if AccountName in BlankAccount_list[i]["name"]:
            if AccountPassword == BlankAccount_list[i]["password"]:
                uid = i
                return 1 #账号与密码正确
            else:
               return  2 #账号的密码输入不正确
        else:
            return 3 #无该账号
        i += 1

#*********************************************************************
def Money_Show(AccountId):
    print("您的余额是:{}元。".format(BlankAccount_list[uid]["money"]))

#*********************************************************************
def Money_Save(AccountId):
    Amount_Save = input("您要存储的金额：")
    input("按回车键确定:")
    BlankAccount_list[uid]["money"] +=  int(Amount_Save)
    print("操作完成")    
#*********************************************************************
def Money_Get(AccountId):
    Amount_get = input("您要取走的金额：")
    input("按回车键确定:")
    BlankAccount_list[uid]["money"] -=  int(Amount_get)
    print("操作成功")
#==================================================================
#====================主程序========================================
while True:
    
    if AccountState_login == 0:
        AccountState_login = 1
        print('='*12,'银行管理系统','='*14)
        Name1 = input("请输入您的用户名：")
        Password1 = input("请输入您的密码：")
        a1 = BankAccount_Login(Name1,Password1)
        if a1 == 3:
            print("无该账号")
            AccountState_login = 2
            input("按回车键继续:")
            AccountState_login = 0
        elif a1 == 2:
            print("账号密码错误")
            AccountState_login = 2
            input("按回车键继续:")
            AccountState_login = 0
        elif a1 == 1:
            AccountState_login = 3
        else:
            print("错误情况：100001")
            Error_Code =100001
            break
    elif AccountState_login == 3:
        #输出初始界面
        print("\n"+"="*12,"银行管理系统","="*14)
        print("{0:1}{1:11}{2:15}".format("","1.查询余额","2.存款"))
        print("{0:1}{1:13}{2:13}".format("","3.取钱","4.退出系统"))
        print("="*40)
        key=int(input('请输入选前对应的数字进行选择：'))
        if key == 1:
            print("\n"+"="*12,"查询余额","="*14)
            Money_Show(uid)
        elif key == 2:
            print("="*12,"存款","="*14)
            Money_Save(uid)
        elif key == 3:
            print("="*12,"取钱","="*14)
            Money_Get(uid)
        elif key == 4:
            print("="*12,"退出操作系统","="*14)
            AccountState_login = 0
        else:
            print("=========无效键盘输入！ =========")
        input("按回车键继续:")

    else:
        break


